﻿package mortal.game.view.guild.util
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.view.common.*;

    public class GuildResourceRecordUitl extends Object
    {
        private var _allItemsMap:Dictionary;
        private var _playerItemsMap:Dictionary;
        private var _notEnoughMap:Dictionary;
        private static var _instance:GuildResourceRecordUitl;

        public function GuildResourceRecordUitl()
        {
            this._allItemsMap = new Dictionary();
            this._playerItemsMap = new Dictionary();
            return;
        }// end function

        public function addItems(param1:SPlayerItem, param2:int, param3:int, param4:int) : void
        {
            this._allItemsMap[param1.itemCode] = int(this._allItemsMap[param1.itemCode]) + param2;
            var _loc_5:* = new SPlayerItem();
            ClassTypesUtil.copyClassValue(_loc_5, param1);
            _loc_5.playerId = param3;
            _loc_5.itemAmount = param2;
            this._playerItemsMap[param3 + "_" + param4] = _loc_5;
            return;
        }// end function

        public function delItems(param1:int, param2:int, param3:int, param4:int) : void
        {
            this._allItemsMap[param1] = int(this._allItemsMap[param1]) - param2;
            var _loc_5:* = this._playerItemsMap[param3 + "_" + param4] as SPlayerItem;
            if (_loc_5.itemAmount > param2)
            {
                _loc_5.itemAmount = _loc_5.itemAmount - param2;
            }
            else
            {
                delete this._playerItemsMap[param3 + "_" + param4];
            }
            return;
        }// end function

        public function getItemNnm(param1:int) : int
        {
            return this._allItemsMap[param1] as int;
        }// end function

        public function getNotEnoughMapNum(param1:int) : int
        {
            if (this._notEnoughMap)
            {
                return this._notEnoughMap[param1] as int;
            }
            return -1;
        }// end function

        public function getPlayerItem(param1:int, param2:int) : SPlayerItem
        {
            return this._playerItemsMap[param1 + "_" + param2];
        }// end function

        public function get allPlayerItem() : Array
        {
            return ArrayUtil.DictAsArr(this._playerItemsMap);
        }// end function

        public function get notEnoughMap() : Dictionary
        {
            var _loc_1:int = 0;
            var _loc_2:String = null;
            this.delNotEnoughMap();
            for (_loc_2 in this._allItemsMap)
            {
                
                _loc_1 = Cache.instance.guild.selfGuildInfo.wareHouse.getWarehouseItemNumByCode(int(_loc_2));
                if (_loc_1 < this._allItemsMap[_loc_2])
                {
                    if (this._notEnoughMap == null)
                    {
                        this._notEnoughMap = new Dictionary();
                    }
                    this._notEnoughMap[_loc_2] = _loc_1;
                }
            }
            return this._notEnoughMap;
        }// end function

        public function delNotEnoughMap() : void
        {
            this.delMap(this._notEnoughMap);
            this._notEnoughMap = null;
            return;
        }// end function

        public function delAllItemsMap() : void
        {
            this.delMap(this._allItemsMap);
            return;
        }// end function

        public function delPlayerItemsMap() : void
        {
            this.delMap(this._playerItemsMap);
            return;
        }// end function

        public function clean() : void
        {
            this.delNotEnoughMap();
            this.delAllItemsMap();
            this.delPlayerItemsMap();
            return;
        }// end function

        private function delMap(param1:Dictionary) : void
        {
            var _loc_2:String = null;
            for (_loc_2 in param1)
            {
                
                delete param1[_loc_2];
            }
            return;
        }// end function

        public function get map() : Dictionary
        {
            return this._allItemsMap;
        }// end function

        public static function get instance() : GuildResourceRecordUitl
        {
            if (_instance == null)
            {
                _instance = new GuildResourceRecordUitl;
            }
            return _instance;
        }// end function

    }
}
